<?php

namespace App\Observers\Train\Port;

use App\Models\Train\TrainTripInfo\TrainExitingPort;
use Illuminate\Support\Facades\Cache;

class ExitingPortObserver
{
    /**
     * Handle the User "created" event.
     *
     * @param TrainExitingPort $port
     *
     * @return void
     */
    public function created(TrainExitingPort $port)
    {
        $cache_key = "Train:ExitingPort:{$port->train_code}:{$port->to_station_code}";
        Cache::put($cache_key, $port, config('trip.ttl.day'));
    }

    /**
     * Handle the User "updated" event.
     *
     * @param TrainExitingPort $port
     *
     * @return void
     */
    public function updated(TrainExitingPort $port)
    {
        $cache_key = "Train:ExitingPort:{$port->train_code}:{$port->to_station_code}";
        Cache::put($cache_key, $port, config('trip.ttl.day'));
    }

    public function saved(TrainExitingPort $port)
    {
        $cache_key = "Train:ExitingPort:{$port->train_code}:{$port->to_station_code}";
        Cache::put($cache_key, $port, config('trip.ttl.day'));
    }
}
